import 'package:chathouse/constant/my_color.dart';
import 'package:chathouse/public/Config.dart';
import 'package:chathouse/util/base_utils.dart';
import 'package:chathouse/util/font_utils.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import '../../model/expert_list_bean.dart';
import 'form_widgets.dart';
import 'package:get/get.dart';

typedef ExpertDialogWidgetSureCallback = Function(int selectedIndex);

class ExpertDialogWidget extends StatefulWidget {
  String title;
  ExpertListBeanTool? expertListBeanTool;
  ExpertDialogWidgetSureCallback sureCallback;

  ExpertDialogWidget(this.title, this.expertListBeanTool, this.sureCallback,
      {Key? key})
      : super(key: key);

  @override
  State<ExpertDialogWidget> createState() => _ExpertDialogWidgetState();
}

class _ExpertDialogWidgetState extends State<ExpertDialogWidget> {
  // List<bool> arraySelected = [];

  @override
  void initState() {
    // arraySelected = widget.expertListBeanTool?.rows?.map((e) {
    //       return false;
    //     }).toList() ??
    //     [];
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return InkWell(
      onTap: () {
        Get.back();
      },
      child: Container(
        color: const Color.fromRGBO(0, 0, 0, 0.65),
        child: Container(
          padding: EdgeInsets.all(18.w),
          margin: EdgeInsets.only(
              left: 30.w, right: 30.w, bottom: 100.w, top: 100.w),
          decoration: BoxDecoration(
              color: const Color.fromRGBO(239, 254, 243, 1),
              borderRadius: BorderRadius.circular(22.w)),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Container(
                    width: 20,
                  ),
                  Expanded(
                    child: Text(
                      widget.title,
                      textAlign: TextAlign.center,
                      style: getTextStyle(30.sp,
                          color: const Color.fromRGBO(79, 141, 89, 1),
                          fontType: FontType.MID),
                    ).setContainer(margin: EdgeInsets.only(bottom: 10.w)),
                  ),
                  InkWell(
                    onTap: () {
                      Get.back();
                    },
                    child: Image.asset(
                      "assets/images/question_close.png",
                      width: 20,
                      height: 20,
                    ),
                  )
                ],
              ),
              Text(
                "專家推介",
                style: getTextStyle(25.sp,
                    color: const Color.fromRGBO(79, 141, 89, 1),
                    fontType: FontType.MID),
              ).setContainer(margin: EdgeInsets.only(bottom: 20.w)),
              Expanded(
                  child: ListView(
                children: (widget.expertListBeanTool?.rows ?? []).map((e) {
                  int index =
                      (widget.expertListBeanTool?.rows ?? []).indexOf(e);
                  return getItem(e.memberImage ?? "", e.membersName ?? "",
                          e.membersCard ?? "")
                      .setOnClickListener(() {
                    // setState(() {
                    //   arraySelected[index] = !arraySelected[index];
                    //   for (int i = 0; i < arraySelected.length; i++) {
                    //     if (i != index) {
                    //       arraySelected[i] = false;
                    //     }
                    //   }
                    // }
                    // );
                    widget.sureCallback(index);
                  });
                }).toList(),
              )),
              Text(
                "除以上專家外，會另加其他專家報價",
                textAlign: TextAlign.center,
                style: getTextStyle(25.sp,
                    color: Colors.black, fontType: FontType.MID),
              ).setContainer(margin: EdgeInsets.only(top: 20.w)),

              // Row(
              //   mainAxisAlignment: MainAxisAlignment.center,
              //   children: [
              //     Container(
              //       margin: EdgeInsets.only(top: 60.w),
              //       padding: EdgeInsets.only(
              //           left: 68.w, right: 68.w, top: 7.w, bottom: 7.w),
              //       decoration: BoxDecoration(
              //           color: const Color.fromRGBO(241, 184, 96, 1),
              //           borderRadius: BorderRadius.circular(19.w)),
              //       child: Text(
              //         "确定",
              //         style: getTextStyle(18.sp,
              //             color: Colors.white, fontType: FontType.MID),
              //       ),
              //     ).setOnClickListener(() {
              //       bool isSelected = arraySelected.firstWhere((element) {
              //         return element;
              //       }, orElse: () {
              //         return false;
              //       });
              //       if (!isSelected) {
              //         debugPrint("no Selected");
              //         return;
              //       }
              //       widget.sureCallback(arraySelected);
              //     })
              //   ],
              // ),
            ],
          ),
        ),
      ),
    );
  }

  Widget getItem(String icon, String title, String subTitle) {
    return Container(
      margin: EdgeInsets.only(bottom: 16.w),
      child: Row(
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          // Container(
          //   width: 27.w,
          //   height: 27.w,
          //   decoration: BoxDecoration(
          //       border: Border.all(color: Colors.black, width: 1.w),
          //       borderRadius: BorderRadius.circular(27.w),
          //       color: selected
          //           ? const Color.fromRGBO(204, 243, 165, 1)
          //           : Colors.white),
          // ),
          ClipRRect(
            borderRadius: BorderRadius.circular(24.w),
            child: ImageUtils.image(icon,
                width: 80.w, height: 80.w, imageType: ImageType.NETWORK),
          ).setContainer(margin: EdgeInsets.only(left: 10.w, right: 10.w)),
          Expanded(
              child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Text(
                title,
                style: getTextStyle(22.sp,
                    color: Colors.black, fontType: FontType.MID),
              ).setContainer(margin: EdgeInsets.only(bottom: 5.w)),
              Text(
                subTitle,
                style: getTextStyle(18.sp, color: Colors.black),
              )
            ],
          ))
        ],
      ),
    );
  }
}
